#[macro_use] extern crate tera;
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate diesel;
use actix_web::{middleware, web, App,error,HttpRequest,Error, HttpServer,HttpResponse, Result,};
use diesel::prelude::*;
use diesel::{r2d2::ConnectionManager,MysqlConnection};
use dotenv::dotenv;
use std::env;
mod controllers;
mod models;
mod libs;
//use crate::libs::lazy_tera::TERA;
mod schema;

fn main()-> std::io::Result<()> {
    std::env::set_var("RUST_LOG", "actix_web=info");
    println!("Hello, world!");
    env_logger::init();
    //let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
    let manager = ConnectionManager::<MysqlConnection>::new("mysql://xxx");
    let pool = r2d2::Pool::builder()
        .build(manager)
        .expect("Failed to create pool.");


    HttpServer::new(move||{
        App::new()
            .data(pool.clone())
            .wrap(middleware::Logger::default()) // enable logger
            .service(web::resource("/").route(web::get().to(controllers::home::index)))
            }
            )
    .bind("127.0.0.1:8081")?
    .run()
}
